package problem.year2021.february;

import java.util.Arrays;

/**
 * 给你一个二维整数数组 matrix， 返回 matrix 的 转置矩阵 。
 * 矩阵的 转置 是指将矩阵的主对角线翻转，交换矩阵的行索引与列索引。
 * 示例 1：
 * 输入：matrix = [[1,2,3],[4,5,6],[7,8,9]]
 * 输出：[[1,4,7],[2,5,8],[3,6,9]]
 * 示例 2：
 * 输入：matrix = [[1,2,3],[4,5,6]]
 * 输出：[[1,4],[2,5],[3,6]]
 * 提示：
 * m == matrix.length
 * n == matrix[i].length
 * 1 <= m, n <= 1000
 * 1 <= m * n <= 105
 * -109 <= matrix[i][j] <= 109
 * 来源：力扣（LeetCode）
 * 链接：https://leetcode-cn.com/problems/transpose-matrix
 * 著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。
 */
public class February25 {
    public int[][] transpose(int[][] matrix) {
        int n = matrix[0].length,m = matrix.length;
        int[][] ints = new int[n][m];
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                ints[i][j] = matrix[j][i];
            }
        }
        return ints;
    }

    public static void main(String[] args) {
//        int[][] ints = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        int[][] ints = new int[][]{{1, 2, 3}, {4, 5, 6}};
        int[][] transpose = new February25().transpose(ints);
        for (int[] e : transpose) {
            System.out.println(Arrays.toString(e));
        }
    }
}
